//
//  XDWelcomeViewController.swift
//  weibo
//
//  Created by lucy on 2016/10/25.
//  Copyright © 2016年 com.huashengHuaSheng. All rights reserved.
//

import UIKit

class XDWelcomeViewController: UIViewController {
    
    override func loadView() {
    
        view = bgImageView
        
    }
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        
    }
    
    //视图将要显示
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.headImageView.snp_updateConstraints { (make) in
            make.top.equalTo(self.view).offset(100)
        }
        UIView.animate(withDuration: 1, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { 
            self.view.layoutIfNeeded()
            }) { (_) in
                UIView.animate(withDuration: 0.25, animations: { 
                    self.messageLabel.alpha = 1
                    }, completion: { (_) in
                      
                        NotificationCenter.default.post(name: NSNotification.Name(rawValue: XDSWITCHVCNOTI), object: "welcomeVc")
                    
                })

        }
    }
    

    //setupUI设置视图
    private func setupUI(){
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        
        //添加约束
        headImageView .snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        }
        
        messageLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp_bottom).offset(20)
        }
    
    
    }
    
    //MARK-懒加载控件
    
    //背景图像
    private lazy var bgImageView : UIImageView = UIImageView(imageViewName: "ad_background")
    
    //用户头像
    private lazy var headImageView : UIImageView = {
        
        let img = UIImageView()
        img.layer.borderColor = THEMECOLOR.cgColor
        img.layer.borderWidth = 1
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        img .xd_setImage(imageWithURl: XDUserAccountViewModel.shareTools.userAccountModel?.avatar_large, placeHolderImageName: "tabbar_compose_friend")
    
        return img
    }()
    
    //欢迎回来
    private lazy var messageLabel: UILabel = {
        let lab = UILabel(textColor: THEMECOLOR, textSize: 18, textContent: "欢迎回来")
        lab.textAlignment = .center
        lab.alpha = 0;
    
        return lab
    }()

}
























